/////////////////////////////////////////////////////////////////////////////////////////////
// MOBs //
//////////
mob
	icon = 'personIcon.dmi'

	var/attackable = 1
	var/HP = 30
	var/inventory = list()
	var/signs = 0
	var/wealth = 0

	Click()
		if(get_dist(src,usr) > 1) return
		attack(src)
		..()

	Del()
		var/obj/item/gold/G = new(loc)
		G.value = rand(1,100)
		..()

	Login()
		icon_state = gender
		players += usr.key
		for (var/obj/teleporter/T in world)
			if (T.linkID == 0001)
				usr.loc = T.loc
		..()
		world << "[usr] has logged in."
		for (var/mob/player/P in world)
			if (P.key == src.key)
				P = usr
				P.UpdateInventory()
		if(src.key in GMs)
			src.verbs += typesof(/GM/verb)

	Logout()
		for (var/obj/sign/S in world)
			if (S.owner == usr.key)
				del(S)
		..()

	proc/attack(mob/M as mob)
		if (attackable == 1)
			if (M.HP <= 0)
				usr << "[M] is already dead!"
			else
				usr << "You attack [M]!"
				oview() << "[usr] attacks [M]!"
				var/damage = rand(1,10)
				world << "[damage] damage!"
				M.HP -= damage
				M.DeathCheck(src)

	proc/DeathCheck(mob/M as mob)
		if (HP <= 0)
			world << "[src] was killed by [M]"

	verb/Get(var/obj/item/O)
		if (istype(O,/obj/item))
			if (istype(O,/obj/item/gold))
				src.wealth += O.value
				usr << "You pick up [O.value] gold!"
				del(O)
			if (istype(O,/obj/item) && !istype(O,/obj/item/gold))
				usr << "You pick up a [O.name]."
				O.Move(src)

	verb/Inventory()
		for (var/mob/player/P in world)
			if (P.key == usr.key)
				if (length(P.inventory) == 0)
					usr << "You have nothing in your inventory."
				else
					for (var/obj/item/I in P.inventory)
						usr << "[I.name] \n"

	verb/MakeSign()
		if (signs < signLimit)
			for (var/obj/sign/S in world)
				if (S.loc == usr.loc)
					usr << "There's already a sign here..."
					return 0

			var/obj/sign/newSign = new()
			newSign.owner = usr.key
			newSign.desc = input("What will your sign read?","Sign text:", "")
			if (!newSign.desc)
				usr << "You leave the sign blank."
			newSign.loc = usr.loc
			usr.signs += 1
		else
			usr << "You cannot make any more signs."

	verb/say(msg as text)
		world << "[usr]: [msg]"

	verb/Wealth()
		usr << "You have [wealth] gold in your purse."

mob/merchant
	attackable = 0
	icon = 'personIcon.dmi'
	icon_state = "neuter"

	Click()
		..()
		src.Buy()

	New()
		..()
		var/obj/item/kazoo/K = new(null)
		K.Move(src)

	proc/Buy()
		var/choice = input("Do you want to buy or sell?") in list("Buy","Sell")
		if (choice == "Buy")
			var/list/shopItems = list("Nothing")
			for (var/obj/item/I in src.contents)
				shopItems += "[I.name]: [I.value]g"
			choice = input("What do you want to buy?") in shopItems
			if (choice != "Nothing")
				usr << "You didn't buy nothing."
				for (var/obj/item/I in src.contents)
					if (I.name == choice)
						usr << "You're about to buy [I.name]"
						for (var/mob/player/P in world)
							if (P.key == usr.key)
								P.wealth -= I.value
								P += I
								usr << "You buy a [I.name]"

	proc/UpdateInventory()
		var/itemCount = 0

		winset(usr, "winMerchant.gridBuy", "show-lines=both; current-cell=1,1")
		usr << output("Merchant Inventory:", "winMerchant.gridBuy")

		for (var/obj/item/I in src)
			++itemCount
			winset(usr, "winMerchant.gridBuy", "current-cell= 1,[itemCount+1]")
			usr << output(I, "winMerchant.gridBuy")

mob/player
	DeathCheck()
		..()
		if (HP <= 0)
			src.HP = 30
			for (var/obj/teleporter/T in world)
				if (T.linkID == 0001)
					src.loc = T.loc

	Get(var/obj/item/O)
		if (O.loc == src)
			usr << "That item is already in your inventory!"
		..()
		src.UpdateInventory()

	proc/UpdateInventory()
		var/itemCount = 0

		winset(src, "default.winInventory", "current-cell=1,1")
		src << output("Inventory:", "default.winInventory")

		for (var/obj/item/I in src)
			++itemCount
			winset(src, "default.winInventory", "current-cell=[itemCount+1],1")
			src << output(I, "default.winInventory")

mob/bug
	icon = 'bug.dmi'
	DeathCheck()
		..()
		if (HP <= 0)
			del(src)